//
//  WSKeyBoardTool.m
//  LuxuryCarUser55like
//
//  Created by 55like on 25/08/2017.
//  Copyright © 2017 55like lj. All rights reserved.
//

#import "WSKeyBoardTool.h"

@implementation WSKeyBoardTool


+(void)TFscrollview:(UIScrollView*)scrollview{
    
    //    UIWindow *scrollview = [[UIApplication sharedApplication] keyWindow];
    
    UIView   *firstRespondtf = [scrollview performSelector:@selector(firstResponder)];
    
    CGFloat frameY;
    frameY=firstRespondtf.frameY;
    UIView*spview;
    for (int i=0; i<20; i++) {
        
        if (i==19) {
            return;
        }
        if (i==0) {
            spview=firstRespondtf.superview;
        }else
            spview=spview.superview;
        if ([spview isKindOfClass:[UIWindow class]]) {
            return;
            break;
        }
        if ([spview isEqual:scrollview]) {
            break;
        }else{
            
            if ([spview isKindOfClass:[UIScrollView class]]) {
                frameY=frameY+spview.frameY;
                
                UIScrollView*scroview=(UIScrollView*)spview;
                
                frameY=frameY-scroview.contentOffset.y;
                
            }else
                
                frameY=frameY+spview.frameY;
            
        }
        
        
        
    }
    
    /*##################计算位置#####################*/
    
    if (firstRespondtf) {
        
        CGFloat h=frameY+30+50-scrollview.frameHeight;
        
        if ([scrollview isKindOfClass:[UITableView class]]) {
            h=frameY+30+100-scrollview.frameHeight;
        }
        h=h>0?h:0;
        scrollview.contentOffset=CGPointMake(scrollview.contentOffset.x,h);
    }
    
}




@end
